/*
 * This file is part of "IdeWiki" project.
 *
 * Copyright (c) 2008 Hendrik Ebel
 * All Rights Reserved.
 *
 * Please visit http://code.google.com/p/idewiki for updates and contact.
 *
 * --LICENSE NOTICE--
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 3
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; If not, see <http://www.gnu.org/licenses/>.
 * --LICENSE NOTICE--
 */
package ws.ebel.idewiki.browser;

import java.util.ArrayList;

/**
 * The Class BrowserHistory.
 */
public final class BrowserHistory {

    /** The items. */
    private ArrayList items;

    /** The location. */
    private int location;

    /**
     * The Constructor.
     */
    public BrowserHistory() {
        items = new ArrayList();
        location = -1;
    }

    /**
     * Add.
     * 
     * @param object the object
     */
    public void add(Object object) {
        location++;
        int numberToRemove = items.size() - location;
        for (int i = 0; i < numberToRemove; i++) {
            items.remove(location);
        }
        items.trimToSize();
        items.add(object);
    }

    /**
     * Size.
     * 
     * @return the size
     */
    public int size() {
        return items.size();
    }

    /**
     * Gets the location.
     * 
     * @return the location
     */
    public int getLocation() {
        return location;
    }

    /**
     * Back.
     * 
     * @return the object
     */
    public Object back() {
        location--;
        Object object = items.get(location);
        return object;
    }

    /**
     * Next.
     * 
     * @return the object
     */
    public Object next() {
        location++;
        return items.get(location);
    }

    /**
     * Checks for previous.
     * 
     * @return true, if has previous
     */
    public boolean hasPrevious() {
        return location > 0;
    }

    /**
     * Checks for next.
     * 
     * @return true, if has next
     */
    public boolean hasNext() {
        return location < items.size() - 1;
    }

    /**
     * Gets the current.
     * 
     * @return the current
     */
    public Object getCurrent() {
        return items.get(location);
    }

    /**
     * To string.
     * 
     * @return the string
     */
    public String toString() {
        return "Location: " + location + ", " + items.toString();
    }

}
